package com.ghck.server.bkcontroller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.ghck.shop.model.Page;
import com.ghck.shop.model.TiXian;
import com.ghck.shop.service.OperateService;

@Controller
@RequestMapping(value="/system/tixian")
public class AdminTiXianController {
	
	@Autowired
	private OperateService operateService;

	
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public String list(TiXian tiXian,
			@RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "10") Integer pageSize,
            HttpServletRequest request){
		int start = 0;
		if(currentPage > 0 ){
			start = ((currentPage-1)*pageSize);
		}
		Page<TiXian> page = new Page<TiXian>(currentPage);
		page.setPageSize(pageSize);
		List<TiXian> list = operateService.adminTixianlist(tiXian, start, pageSize);
		page.setResultRows(list);
		page.setTotalRow(operateService.countAdminTixianlist(tiXian));
		request.setAttribute("page", page);
		return "back/tixian/list";
	}
	@RequestMapping(value="/complete/{id}",method=RequestMethod.GET)
	public String completeTiXian(@PathVariable("id")Integer id){
		operateService.tixianComplete(id);
		return "redirect:/system/tixian/list";
	}
}
